package com.caishi.lkx.common;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

/**
 * @Author wsc
 * @Date 2024/3/12 9:38
 **/
public class VipsmartAesUtil {
    private static final AES aes;

    static {
        byte[] key = {0x12, 0x34, 0x56, 0x78, (byte) 0x90, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF,
                (byte) 0xFE, (byte) 0xDC, (byte) 0xBA, (byte) 0x98, 0x76, 0x54, 0x32, 0x10,
                0x0F, (byte) 0xE1, (byte) 0xD2, (byte) 0xC3, (byte) 0xB4, (byte) 0xA5, (byte) 0x96, (byte) 0x87,
                0x78, 0x69, 0x5A, 0x4B, 0x3C, 0x2D, 0x1E, 0x0F};
        byte[] iv = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
        aes = new AES(Mode.CBC, Padding.PKCS5Padding, key, iv);
    }

    public static String encryptStr(String data) {
        if (StrUtil.isBlank(data)) return null;
        return aes.encryptBase64(data);
    }

    public static String decryptStr(String data) {
        if (StrUtil.isBlank(data)) return null;
        return aes.decryptStr(data);
    }
}
